﻿Namespace PL.TSMSDK
    Public Class Employee_PL
        Inherits PLBase


        Public EmplCDSeq As Short = 3


        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub
        Public Sub New()
            MyBase.New()
        End Sub

        Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs) Handles MetaDataTable.OnRowUpdating


            'Pour le Save sur un ADD on assign la sequence
            'SSPP#..... : All String Shall recpect SQL CASING
            Me.MetaDataTable.Adapter.InsertCommand.Parameters("@GenerateSEQ").Value = EmplCDSeq
            Me.MetaDataTable.Adapter.UpdateCommand.Parameters("@GenerateSEQ").Value = EmplCDSeq



        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Shared Function GetEmployeeIdByUserName(ByVal username As String) As Guid
            Dim emplId As Guid = Nothing
            Using mq As MetaQuery = MetaQuery.GetMetaQueryByName("Employee")
                mq.SQLWhere = String.Format("UserName = '{0}'", username)
                mq.FillResultQuery()
                If mq.ResultQuery.Rows.Count > 0 Then
                    emplId = CType(mq.ResultQuery.Rows(0).Item("EmplID"), Guid)
                End If
            End Using
            Return emplId
        End Function

        Public Shared Function GetEmployeeRow(ByVal username As String) As DataRow
            Dim aRow As DataRow = Nothing
            Using mq As MetaQuery = MetaQuery.GetMetaQueryByName("Employee")
                mq.SQLWhere = String.Format("UserName = '{0}'", username)
                mq.FillResultQuery()
                If mq.ResultQuery.Rows.Count > 0 Then
                    aRow = mq.ResultQuery.Rows(0)
                End If
            End Using
            Return aRow
        End Function

        Public Shared Function GetEmployeeRow(ByVal emplID As Guid) As DataRow
            Dim aRow As DataRow = Nothing
            Using mq As MetaQuery = MetaQuery.GetMetaQueryByName("Employee")
                mq.SQLWhere = String.Format("emplID = '{0}'", emplID)
                mq.FillResultQuery()
                If mq.ResultQuery.Rows.Count > 0 Then
                    aRow = mq.ResultQuery.Rows(0)
                End If
            End Using
            Return aRow
        End Function

        Sub NewRecord(row As DataRow)
            'Si on arrive d'un TreeList...
            If Me.ID IsNot Nothing Then
                row("EmplID") = ID
            End If
        End Sub


    End Class
End Namespace
